//
//  SchoMixTypeImageView.m
//  高仿暴走斗图
//
//  Created by key on 16/5/3.
//  Copyright © 2016年 huangsongyao. All rights reserved.
//

#import "SchoMixTypeImageView.h"

#define CANCEL_IMG_SIZE         20.0f

@interface SchoMixTypeImageView()<UIGestureRecognizerDelegate>

@property (nonatomic, assign, readonly) BOOL isSelectCancel;
@property (nonatomic, strong) UIImageView *cancelImageView;
@property (nonatomic, strong) UIImageView *topImageView;

@end

@implementation SchoMixTypeImageView

- (instancetype)initWithFrame:(CGRect)frame andMixType:(kSchoMixType)mixType {
    
    if (self = [super initWithFrame:frame]) {
        
        [self setupMixType:mixType];
    }
    return self;
}

- (void)setupMixType:(kSchoMixType)mixType {
    
    _contentImageView = [NSObject createImgWithImage:[[HSYColorHelper shareInstance] canvasImageWithColor:[UIColor greenColor]]
                                              hImage:[[HSYColorHelper shareInstance] canvasImageWithColor:[UIColor greenColor]]
                                       clipsToBounds:YES
                                             vcModel:UIViewContentModeScaleToFill];
    [self addSubview:self.contentImageView];
    self.contentImageView.frame = self.bounds;
    
    self.cancelImageView = [NSObject createImgWithImage:[UIImage imageNamed:@"delete_edit"]
                                                 hImage:[UIImage imageNamed:@"delete_edit"]
                                          clipsToBounds:YES
                                                vcModel:UIViewContentModeScaleToFill];
    self.contentImageView.userInteractionEnabled = YES;
    [self addSubview:self.cancelImageView];
    self.cancelImageView.frame = (CGRect){self.contentImageView.viewWidth - CANCEL_IMG_SIZE, 0, CANCEL_IMG_SIZE, CANCEL_IMG_SIZE};
    
    if (mixType == kSchoMixTypeAudio ||
        mixType == kSchoMixTypeVideo) {
        UIImage *image = nil;
        if (mixType == kSchoMixTypeAudio) {
            
            image = [UIImage imageNamed:@"time"];
        } else {
            
            image = [UIImage imageNamed:@"play"];
        }
        self.topImageView = [NSObject createImgWithImage:image
                                                  hImage:image
                                           clipsToBounds:YES
                                                 vcModel:UIViewContentModeScaleToFill];
        [self addSubview:self.topImageView];
        self.topImageView.frame = self.bounds;
    }
    
    
    
    [self addGestureRecognizer:[UIView addGestureRecognizerWithGesturesType:kGesturesTypeTapGestureRecognizer action:@selector(selectView:) delegate:self]];
    
}

- (void)selectView:(UITapGestureRecognizer *)tap {
    
    CGPoint point = [tap locationInView:self.contentImageView];
    NSLog(@"point :%@", NSStringFromCGPoint(point));
    if (point.y >= 0 && point.y <= self.cancelImageView.viewHeight) {
        if (point.x >= self.contentImageView.viewWidth - self.cancelImageView.viewWidth && point.x <= self.contentImageView.viewWidth) {
            
            if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectCancelSiganl)]) {
                [self.delegate didSelectCancelSiganl];
            }
        } else {
            
            if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectContentImgSignal)]) {
                [self.delegate didSelectContentImgSignal];
            }
        }
    } else {
        
        if (self.delegate && [self.delegate respondsToSelector:@selector(didSelectContentImgSignal)]) {
            [self.delegate didSelectContentImgSignal];
        }
    }
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    
    
}

@end
